package com.cn.lp.export.server.entity;

import com.cn.lp.export.server.base.utils.ObjectAide;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * 数据仓库
 * Created by qirong on 2020/10/18.
 */
@Component
public class ExportDataDepository {

    @Autowired
    private ExportSyncDataDao exportSyncDataDao;

    /**
     * 根据导出任务获取上传数据列表
     * @param task
     * @return
     */
    public List<Map<String, Object>> getDataList(ExportTask task) {
        List<ExportSyncData> syncDataList = exportSyncDataDao.findByTaskIdOrderBySort(task.getId());
        List<Map<String, Object>> dataList = new ArrayList<>();
        syncDataList
            .stream()
            .map(syncData -> ObjectAide.blobToObject(syncData.getData(), ExportData.class))
            .map(ExportData::getDataList)
            .forEachOrdered(dataList::addAll);
        return dataList;
    }

}
